#include<iostream>
#include"log.hpp"
#include"comm.hpp"

int main()
{
    int shmid=GetShm();
    std::cout<<shmid<<std::endl;
    char*shmaddr=(char*)shmat(shmid,nullptr,0);
    std::cout<<shmaddr<<std::endl;
    if(shmaddr==(char*)-1)
    {
        perror("shmat");
        return 1;
    }
    int fd=open(FIFO_FILE,O_WRONLY);
    if(fd<0)
    {
        perror("open");
        return 1;
    }
    // char buffer[1024];
    while(true)
    {
        std::cout<<"Please Enter@ ";
        fgets(shmaddr,4096,stdin);
        write(fd,shmaddr,strlen(shmaddr));
        // write(fd,buffer,sizeof(buffer));
        std::cout<<"write success.."<<std::endl;
    }
    shmdt(shmaddr);
    shmctl(shmid,IPC_RMID,nullptr);
    close(fd);
    return 0;
}